﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Project_2._2.Models;
using PagedList;
using PagedList.Mvc;
using Project_2._2.ViewModels;

namespace Project_2._2.Controllers
{
    public class XeController : Controller
    {
        private QuanLyThueXeEntities db = new QuanLyThueXeEntities();

        #region chi tiet xe
        // GET: /Xe/

        public ActionResult ChiTiet( int id)
        {
            return View();
        }

        #endregion

        #region danh sach xe theo dich vu
        public ActionResult DanhSachDichVu( int? page , int id)
        {
            var car   = (from gia in db.GiaXes join xe in db.Xes on gia.XeId equals xe.XeId
                                                            join tHieu in db.ThuongHieux on xe.ThuongHieuId equals tHieu.ThuongHieuId
                                                            join Loai in db.LoaiXes on xe.LoaiXeId equals Loai.LoaiXeId
                                                            join dv in db.DichVuThueXes on gia.DichVuId equals dv.DichVuId
                                                            where gia.DichVuId == id
                                                            select new
                                                            {
                                                                id = xe.XeId,
                                                                name = xe.TenXe,
                                                                THieu = tHieu.TenThuongHieu,
                                                                DoiXe = xe.DoiXe,
                                                                Color = xe.MauXe,
                                                                loai = Loai.TenLoaiXe,
                                                                Gia = gia.Gia,
                                                                hinh = xe.HinhAnhDaiDien,
                                                                dichvu = dv.TenDichVu
                                                            }).ToList().ToPagedList( page?? 1, 5); 
          
            string str ="";
            if (car.Count > 0)
        {
                for (int j = 0; j < car.Count; j++)
                {
                     if( j % 2 == 0)
                     {
                        str += "<div class='sp'>";
                         str +=    "<div class='sp_name'>"+car[j].name+"</div>";
                         str +=    "<div>";
                         str +=        "<div>";
                         str += "<img src=\"../Images/Cars/" + car[j].hinh + "\" style='cursor:pointer' width='160' height='110' onmouseover=\"dotooltip('../Images/Cars/" + car[j].hinh + "')\" onmouseout='hide()' />";
                         str += "</div>";
                          str +=       "<div class='sp_detail'>";
                          str +=           "Hiệu : "+car[j].THieu+"<br />";
                          str +=           "Dòng xe: Civic<br />";
                          str +=           "Đời xe : "+car[j].DoiXe +"<br />";
                          str +=           "Kiểu xe : "+car[j].loai+"<br />";
                           str +=          "Màu xe : "+car[j].Color+"<br />";
                          str +=           "Giá thuê tháng :<span> "+string.Format("{0:#,### đ}", car[j].Gia)+"</span><br />";

                          str +=       "</div>";
                          str +=       "<div style='clear:right'></div>";
                          str +=       "<div style='text-align:center; margin-bottom:10px'>";
                           str +=          "<input type='button' value='Đặt Xe' class='Button' style=' margin-top:5px' />";
                           str += "<a href="+Url.Action("ChiTiet", "Xe", new {  id =  car[j].id })+" style='font-size:13px; text-decoration:none; padding-top:5px' class='Button'>Xem Chi tiết</a>";
                          str +=       "</div>";
                         str +=    "</div>";
                      str +=   "</div>";
                     }
                    else
                     {
                        str += "<div class='sp-left'>";
                            str +=    "<div class='sp_name'>"+car[j].name+"</div>";
                         str +=    "<div>";
                         str +=        "<div>";
                          str +=           "<img src=\"/Images/Cars/"+car[j].hinh+"\" style='cursor:pointer' width='160' height='110' onmouseover=\"dotooltip('/Images/Cars/"+car[j].hinh+"')\" onmouseout='hide()' />";
                          str +=       "</div>";
                          str +=       "<div class='sp_detail'>";
                          str +=           "Hiệu : "+car[j].THieu+"<br />";
                          str +=           "Dòng xe: Civic<br />";
                          str +=           "Đời xe : "+car[j].DoiXe +"<br />";
                          str +=           "Kiểu xe : "+car[j].loai+"<br />";
                           str +=          "Màu xe : "+car[j].Color+"<br />";
                          str +=           "Giá thuê tháng :<span> "+string.Format("{0:#,### đ}", car[j].Gia)+"</span><br />";

                          str +=       "</div>";
                          str +=       "<div style='clear:right'></div>";
                          str +=       "<div style='text-align:center; margin-bottom:10px'>";
                           str +=          "<input type='button' value='Đặt Xe' class='Button' style=' margin-top:5px' />";
                           str += "<a href=" + Url.Action("ChiTiet", "Xe", new { id = car[j].id }) + " style='font-size:13px; text-decoration:none; padding-top:5px' class='Button'>Xem Chi tiết</a>";
                          str +=       "</div>";
                         str +=    "</div>";
                      str +=   "</div>";
                        str += "<div style='clear:both'></div>";
                    }
                }
                ViewBag.tieude = car[0].dichvu;
        }
            ViewBag.str = str;
            
            return View( );
        }

        #endregion

        #region danh sach xe theo loai xe
        public ActionResult DanhSachLoaiXe(int id)
        {
            return View();
        }
             
        #endregion
    }
}
